import {
  get,
  post,
  put,
} from "./base_service"


/**
 * 视频相关接口
 *
 * allen  2021-08-24
 */

/**
 * 查询视频列表
 * @param {*} page 
 * @param {*} pageSize 
 */
const queryVideoList = (page, pageSize, tag, words) => {
  return new Promise((resolve, reject) => {
    get("/video/list?page=" + page + "&pageSize=" + pageSize + "&tag=" + tag + "&words=" + words).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 查询视频详情
 * @param {*} page 
 * @param {*} pageSize 
 */
const queryVideoDetail = (id) => {
  return new Promise((resolve, reject) => {
    get("/video/detail?id=" + id).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 查询视频详情
 * @param {*} page 
 * @param {*} pageSize 
 */
const queryVideoCommentList = (videoId, page, pageSize, type = 1) => {
  return new Promise((resolve, reject) => {
    get("/video/comment/list?id=" + videoId + "&page=" + page + "&pageSize=" + pageSize + "&type=" + type).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 视频创建评论
 * @param {*} data 
 */
const createComment = (data) => {
  return new Promise((resolve, reject) => {
    post("/video/comment/create", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 点赞
 * @param {*} data 
 */
const starComment = (id) => {
  return new Promise((resolve, reject) => {
    get("/video/star/comment?id=" + id).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

module.exports = {
  queryVideoDetail,
  queryVideoCommentList,
  queryVideoList,
  starComment,
  createComment
}
